<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Myclass {

    public function randomkeys($length=8)
    {
     $pattern='1234567890abcdefghijklmnopqrstuvwxyz';
     $key = '';
     for($i=0;$i<$length;$i++)
     {
       $key .= $pattern{mt_rand(0,15)};    
     }
     return $key;
    }
	
	public function v_post($url, $data){
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		return curl_exec($ch);
	}
	
	public function SendMail($subject,$message, $conf){
		//配置邮箱参数
		$config['protocol']= 'smtp';
		
		$config['smtp_host'] = $conf->smtpserver;  
		$config['smtp_user'] = $conf->smtpuser;  
		$config['smtp_pass'] = $conf->smtppassword;  
		$config['smtp_port'] = '465';
		
		  
		$config['charset'] = 'utf-8';  
		$config['wordwrap'] = TRUE;  
		$config['mailtype'] = 'html'; 
		$config['newline'] = "\r\n";
		$config['crlf'] = "\r\n";  
                
		
		$sdk =& get_instance();
		$sdk->load->library('email',$config); 
		
		//开始发送邮件
		$sdk->email->clear();
               // var_dump($config);die(0);
		$sdk->email->to($conf->email);
		$sdk->email->from($conf->smtpuser);
		$sdk->email->subject($subject);
		$sdk->email->message($message);
		$result = $sdk->email->send();
              
		
               
                   //echo $sdk->email->print_debugger();
                
                //die(0);
		//echo $sdk->email->print_debugger();
	}
	
	public function pagination($curr_page='',$total_page='',$url='',$getname='',$getnum=''){
		
		if(!$total_page||!$curr_page||!$url) return false;
		
		$getinfo = $getname&&$getnum?'?'.$getname.'='.$getnum:'';
		
		$total_page = ceil($total_page);
		
		$pagination = '';
				
		$pagination .= '<ul class="pagination" style="float: right;">';
		
		if($curr_page>1){
			
			$pagination .= '<li><a href="'.$url.'/'.($curr_page-1).$getinfo.'">&laquo;</a></li>';
		}
		
		if($total_page>8){
			
			if($curr_page>=4){
				
				$pagination .= '<li><a href="'.$url.'/1'.$getinfo.'">1</a></li>';
					
				$pagination .= '<li><a href="#">...</a></li>';
					
				if($curr_page+2<$total_page){
				
					for ($i=$curr_page-3;$i<=$curr_page+3;$i++){
							
						if ($i == $curr_page) {
								
							$pagination .= '<li><a href="#">'.$i.'</a></li>';
								
							continue;
								
						}
				
						$pagination .= '<li><a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a></li>';
							
					}
				
					$pagination .= '<li><a href="#">...</a></li>';
				
					$pagination .= '<li><a href="'.$url.'/'.$total_page.$getinfo.'">'.$total_page.'</a></li>';
				
				}else{
				
					for ($i=$curr_page-2;$i<=$total_pages;$i++){
							
						if ($i == $curr_page) {
								
							$pagination .= '<li><a href="#">'.$i.'</a></li>';
								
							continue;
								
						}
							
						$pagination .= '<li><a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a></li>';
							
					}
				
				}
				
				
			}else{

				for ($i=1;$i<=$curr_page+2;$i++){
				
					if ($i == $curr_page) {
							
						$pagination .= '<li><a href="#">'.$i.'</a></li>';
							
						continue;
				
					}
						
					$pagination .= '<li><a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a></li>';
				
				}
					
				$pagination .= '<li><a href="#">...</a></li>';
					
				$pagination .= '<li><a href="'.$url.'/'.$total_page.$getinfo.'">'.$total_page.'</a></li>';
				
				
			}
		}else{
			
			for($i=1;$i<=$total_page;$i++){
				
				if($i == $curr_page){
					
					$pagination .= '<li><a href="#">'.$i.'</a></li>';
					
					continue;
				}
				
				$pagination .= '<li><a href="'.$url.'/'.$i.$getinfo.'">'.$i.'</a></li>';
				
			}
		
		}
		
		if($curr_page<$total_page){
			$pagination .= '<li><a href="'.$url.'/'.($curr_page+1).$getinfo.'">&raquo;</a></li>';				
		}
		
		$pagination .= '</ul>';
		
		return $pagination;
		
	}
	
	
	
	
}